package com.mobi.cacti.ns.view;

import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.app.Fragment;
import org.holoeverywhere.widget.ProgressBar;
import org.holoeverywhere.widget.TextView;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.mobi.cacti.R;
import com.mobi.cacti.rabbit.controllers.TicketDetailActivityController;
import com.mobi.cacti.rabbit.controllers.TicketDetailActivityControllerCallback;
import com.mobi.cacti.rabbit.response.ReqTicketDetail;

public class TicketDetailActivity extends Fragment implements
		TicketDetailActivityControllerCallback {

	private TicketDetailActivityController ticketDetailActivityController;
	private String ticketId;

	private TextView ticketNoTextView;
	private TextView ticketStatusTextView;
	private TextView faultDescriptionTextView;
	private TextView faultDateTextView;
	
	private ProgressBar progressBar;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ticketDetailActivityController = TicketDetailActivityController
				.getInstance();
		ticketDetailActivityController.delegate = this;
		
		Bundle bundle = getArguments();
		ticketId = bundle.getString("ticketId");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View v = LayoutInflater.from(getActivity()).inflate(
				R.layout.ticketdetail_layout, null);

		progressBar = (ProgressBar) v.findViewById(R.id.progressbar);
		
		ticketNoTextView = (TextView) v.findViewById(R.id.ticketno);
		ticketStatusTextView = (TextView) v.findViewById(R.id.ticketstatus);
		faultDescriptionTextView = (TextView) v
				.findViewById(R.id.faultdescription);
		faultDateTextView = (TextView) v.findViewById(R.id.faultdate);

		ticketNoTextView.setText("Ticket No. ");
		ticketStatusTextView.setText("Ticket Status: ");
		faultDescriptionTextView.setText("Fault Description: ");
		faultDateTextView.setText("Fault Date: ");

		ticketDetailActivityController.loadTicketDetailForTicketId(this.getActivity(),ticketId);

		return v;
	}

	@Override
	public void ticketDetailActivityControllerDidLoadTicketDetail(
			ReqTicketDetail ticketDetail) {
		progressBar.setVisibility(View.GONE);
		
		ticketNoTextView.setText("Ticket No. " + ticketDetail.ticketNo);
		ticketStatusTextView.setText("Ticket Status: " + ticketDetail.ticketStatus);
		faultDescriptionTextView.setText("Fault Description: " + ticketDetail.faultTypeCode);
		faultDateTextView.setText("Fault Date: " + ticketDetail.faultDate);
	}

}
